<!DOCTYPE html>
<body>
<!-- based on WebKit test: https://trac.webkit.org/changeset/160182 -->
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
function stripSpaces(str) {
  return str.replace(/[\s\n]/gm, '');
}
</script>
<form>
  <template id="templateWithFormInsideForm">
    <form>
      <input>
    </form>
  </template>
</form>
<script>
test(function() {
  var templateWithFormInsideForm = document.getElementById('templateWithFormInsideForm');
  assert_equals(stripSpaces(templateWithFormInsideForm.innerHTML), '<form><input></form>');
  var formInsideTemplate = templateWithFormInsideForm.content.firstElementChild;
  assert_equals(formInsideTemplate.localName, 'form');
  var inputInsideTemplate = templateWithFormInsideForm.content.querySelector('input');
  assert_equals(inputInsideTemplate.form, formInsideTemplate);
  assert_equals(formInsideTemplate.firstElementChild, inputInsideTemplate);
}, 'Form control elements inside templates should not be associated with forms outside the template.');
</script>
<template id="templateWithNestedForms">
  <form>
    <form></form>
  </form>
</template>
<script>
test(function() {
  var templateWithNestedForms = document.getElementById('templateWithNestedForms');
  assert_equals(stripSpaces(templateWithNestedForms.innerHTML), '<form><form></form></form>');
}, '(Nested) form elements inside templates should be parsed correctly.');
</script>
